package com.opesoft.calendar.biz;

import java.util.List;

import javax.persistence.EntityManager;

import com.opesoft.calendar.model.NoteType;
import com.opesoft.pf.jpa.SessionManager;

public class NoteTypeBO
{
	public void save(NoteType noteType)
	{
		EntityManager em=SessionManager.open();
		em.persist(noteType);
		SessionManager.commit();
	}

	@SuppressWarnings("unchecked")
	public String[][] searchNoteTypes()
	{
		EntityManager em=SessionManager.open();

		List<NoteType> list=em.createQuery("select x from NoteType x").getResultList();
		if(list!=null&&list.size()>0)
		{
			String[][] result=new String[list.size()][];
			for(int i=0;i<list.size();i++)
			{
				NoteType nt=list.get(i);
				String[] line=new String[4];
				line[0]=nt.getId()+"";
				line[1]=nt.getName();
				line[2]=nt.getIco();
				line[3]=nt.getRemark();

				result[i]=line;
			}

			SessionManager.rollback();
			return result;
		}

		return new String[0][];
	}

	public NoteType findNoteType(long id)
	{
		EntityManager em=SessionManager.open();
		NoteType nt=(NoteType)em.createQuery("select x from NoteType x where x.id="+id).getSingleResult();
		return nt;
	}

}
